package mock.servicesdirectory.premises.web.action;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import mock.servicesdirectory.common.entities.Premise;
import mock.servicesdirectory.premises.business.businessinterface.PremiseBo;


import com.opensymphony.xwork2.ActionSupport;

public class PremiseListAction extends ActionSupport {
	
	public int getPremiseId() {
		return premiseId;
	}

	public void setPremiseId(int premiseId) {
		this.premiseId = premiseId;
	}

	private int premiseId;
	private String locationName;
	private String locationDescription;
	private String address1;
	private Boolean isNewShop;
	
	public String getLocationName() {
		return locationName;
	}

	public void setLocationName(String locationName) {
		this.locationName = locationName;
	}

	public String getLocationDescription() {
		return locationDescription;
	}

	public void setLocationDescription(String locationDescription) {
		this.locationDescription = locationDescription;
	}

	public String getAddress1() {
		return address1;
	}

	public void setAddress1(String address1) {
		this.address1 = address1;
	}

	public Boolean getIsNewShop() {
		return isNewShop;
	}

	public void setIsNewShop(Boolean isNewShop) {
		this.isNewShop = isNewShop;
	}

	
	
	
	public PremiseBo getPremiseBo() {
		return premiseBo;
	}

	public void setPremiseBo(PremiseBo premiseBo) {
		this.premiseBo = premiseBo;
	}

	private List<Premise> gridModel;	
	//TrustRegionBo trustRegionBo;
	private PremiseBo premiseBo;
	private Integer rows = 0;	
	private Integer page = 0;	
	private String sord;	
	private String sidx;
	private String searchField;
	private String searchString;
	private String searchOper;	
	private Integer total = 0;
	private Integer records = 0;
	
	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public String getSearchOper() {
		return searchOper;
	}

	public void setSearchOper(String searchOper) {
		this.searchOper = searchOper;
	}

	public String getSearchString() {
		return searchString;
	}

	public void setSearchString(String searchString) {
		this.searchString = searchString;
	}

	public String getSearchField() {
		return searchField;
	}

	public void setSearchField(String searchField) {
		this.searchField = searchField;
	}

	public String getSidx() {
		return sidx;
	}

	public void setSidx(String sidx) {
		this.sidx = sidx;
	}

	public String getSord() {
		return sord;
	}

	public void setSord(String sord) {
		this.sord = sord;
	}

	public List<Premise> getGridModel() {
		return gridModel;
	}

	public void setGridModel(List<Premise> gridModel) {
		this.gridModel = gridModel;
	}

	public String execute() {		
		records = 30;
		rows = 10;
		setGridModel(premiseBo.getPremise());
		setTotal((int) Math.ceil((double) records / (double) rows));

		return SUCCESS;
	}
	public String listPremiseOfOrganisation(int orgid){
		records=30;
		rows=10;
		setGridModel(premiseBo.getPremise(orgid));
		setTotal((int) Math.ceil((double) records / (double) rows));

		return SUCCESS;
	}
	/*public String getJSON() {
		return execute();
	}
	*/
	public String back(){
		
		return SUCCESS;
	}
	
	public String create(){
		
		return SUCCESS;
	}
	
	  /**
     * Method used to redirect to Trust Region List page from menu list
     * @return
     */
    public String listPremises(){
    	return SUCCESS;
    }
    
    /**
     * Method used to redirect to Governmen tOffice Region List page from menu list
     * @return
     */
    public String listGovernmentOfficeRegion(){
    	return SUCCESS;
    }
    /**
	 * Method used to process addPremiseAction
	 * @return
	 */
	
	public String addPremise(){
		Premise premise =new Premise();
		if(premiseId!=-1){
			premise.setPremiseId(premiseId);
		}
		premise.setLocationName(locationName);
		premise.setLocationDescription(locationDescription);
		premise.setAddress1(address1);
		premise.setIsNewShop(isNewShop);
		premiseBo.addPremise(premise);
		return SUCCESS;
	}
}
